<template>
  <div class="app-container">
    <el-card>
      <el-tabs v-model="activeName">
        <el-tab-pane label="基本设置" name="base">
          <BaseSet ref="BaseSet" :backtrack="backtrack" @handleActive="handleActive"/>
        </el-tab-pane>
        <el-tab-pane :label="item.stepName" v-for="(item, index) in backtrack.stepList" :key="index" :name="index + ''">
          <WorkflowSet v-if="item.listType === Object.keys(listType)[0]" :commonPara="backtrack.commonPara" :step="item" />
          <DataTabSet v-if="item.listType === Object.keys(listType)[1]" :commonPara="backtrack.commonPara" :step="item" />
        </el-tab-pane>
      </el-tabs>
      <el-row style="margin-top: 15px; text-align: center;">
        <el-button type="primary" @click="handleSave()">保存</el-button>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import enums from '@/views/workflow/utils/enum'
import { save } from '@/api/workflow/backtrack'
import BaseSet from './components/Set/BaseSet'
import WorkflowSet from './components/Set/WorkflowSet'
import DataTabSet from './components/Set/DataTabSet'

export default {
  components: { 
    BaseSet,
    WorkflowSet,
    DataTabSet
  },
  data() {
    return {
      activeName: 'base',
      backtrack: {
        dataBacktrackName: '',
        commonPara: [],
        stepList: [],
        stepNum: 0
      }
    }
  },
  computed: {
    listType() {
      return enums.LIST_TYPE
    },
  },
  watch: {
    
  },
  filters: {},
  created() {
    
  },
  methods: {
    handleActive(backtrack) {
      this.backtrack = JSON.parse(JSON.stringify(backtrack))
    },
    handleSave() {
      const data = JSON.parse(JSON.stringify(this.backtrack))
      if (data.stepList && data.stepList.length) {
        save(data).then(res => {
          this.$message.success('保存成功')
          this.$router.push(
            {
              name: 'backtrackSetList'
            }
          )
        })
      } else {
          this.$message.error('请先添加步骤')
      }

    }
  }
}
</script>
